<template>
  <div>
    <a-card :bordered="false">
      <f-search-form :more="false" @searchHandler="searchHandler">
        <f-search-form-item label="供货商" name="supplierId"/>
      </f-search-form>
      <f-table ref="table" rowKey="paymentId" :columns="columns" :multiple="false" :operator="operator" :params="queryParam" :api="api.payment" handler="refundPaymentPageListHandler">
         <span slot="paymentState" slot-scope="text, record, index">
            <a-tag color="#87d068" v-if="text==0">未提交</a-tag>
             <a-tag color="#87d068" v-if="text==1" @click="processImg(record)">{{record.taskName}}</a-tag>
        </span>
        <span slot="action" slot-scope="text, record">
          <template>
            <a @click="startProcess(record)" v-if="record.paymentState==0">提交审批</a>
            <a @click="completeTask(record)" v-if="record.taskDefinitionKey&&record.taskDefinitionKey=='__initiator__'">提交审批</a>
            <a-divider type="vertical" v-if="record.paymentState==0||(record.taskDefinitionKey&&record.taskDefinitionKey=='__initiator__')"/>
            <a @click="$refs.drawer.showDrawer(record,'form2')">查看</a>
            <a-divider type="vertical"/>
          </template>
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
                <a-menu-item v-if="record.paymentState==1">
                <a href="javascript:;" @click="processImg(record)">审批进度</a>
              </a-menu-item>
              <a-menu-item v-if="record.paymentState==0">
                <a href="javascript:;" @click="$refs.table.del(record,{handlerName:'refundPaymentDeleteHandler'})">删除</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </f-table>
      <refund-drawer ref="drawer" @success="onLoad"></refund-drawer>
      <process-image ref="processImg" v-if="processImageVisible" :visible.sync="processImageVisible" :processInstanceId="processInstanceId"></process-image>
    </a-card>
  </div>
</template>
<script>
  import refundDrawer from './refund_drawer.vue'
  import api from './../js/api'
  import ProcessImage from '../../../flowable/process/process_image'
  export default {
    name: 'TableList',
    components: {
      refundDrawer,ProcessImage
    },
    data() {
      let me = this
      //操作按钮
      let operator = []
      operator.push({
        name: '添加返款单',
        icon: 'plus',
        that: this,
        handler: function(table, that) {
          that.$refs.drawer.showDrawer({}, 'form1')
        }
      })
      return {
        api: Object.assign(api, this.api),
        //列表初始化查询参数
        queryParam: {},
        processImageVisible: false,
        // 表头
        columns: [
          {
            title: '#',
            width: '60',
            align: 'center',
            customRender: (text, record, index) => index + 1
          },
          {
            title: '返款单号',
            align: 'center',
            dataIndex: 'paymentNo'
          },
          {
            title: '税金单号',
            align: 'center',
            dataIndex: 'ipNo'
          },
          {
            title: '供货商',
            align: 'center',
            dataIndex: 'supplierName'
          },
          {
            title: '开票单位',
            align: 'center',
            dataIndex: 'invoiceunitName'
          },
          {
            title: '收款账户',
            align: 'center',
            dataIndex: 'bankName'
          },
          {
            title: '开票金额',
            align: 'center',
            dataIndex: 'invoiceAmount'
          },
          {
            title: '应返金额',
            align: 'center',
            dataIndex: 'supplierRetable'
          },
          {
            title: '返款金额',
            align: 'center',
            dataIndex: 'amount'
          },
          {
            title: '返款日期',
            align: 'center',
            dataIndex: 'amountDate'
          },
          {
            title: '申请人',
            align: 'center',
            dataIndex: 'nickName'
          },
          {
            title: '返款状态',
            align: 'center',
            dataIndex: 'paymentState',
            scopedSlots: { customRender: 'paymentState' }
          },
          {
            title: '操作',
            align: 'center',
            scopedSlots: { customRender: 'action' }
          }
        ],
        operator: operator
      }
    },
    created() {
    },
    methods: {
      processImg(order) {
        this.processInstanceId = order.processInstanceId
        this.processImageVisible = true
      },
      //重新提交
      completeTask(paymentId) {
        this.http.confirm(this, {
          content: '确认提交审批吗?',
          url: api.tasktodo.complete,
          requestBody: true,
          data: {
            taskId: paymentId.taskId
          },
          success: function(me, data) {
            me.$refs.table.refresh()
          }
        })
      },
      startProcess(order) {
        this.http.confirm(this, {
          content: '确认提交审批吗?',
          url: api.processInstance.start,
          requestBody: true,
          data: {
            handlerName: 'paymentRefundStartProcessHandler',
            businessKey: order.paymentId
          },
          success: function(me, data) {
            me.$refs.table.refresh()
          }
        })
      },
      onLoad() {
        this.$refs.table.refresh()
      }
    }
  }
</script>
